package cn.superchart.common.enums;

import java.util.Arrays;

public enum DataSourceDriverEnum implements DriverEnum{


	MYSQL {
		public Integer getCode() {
			return 1;
		}

		public String[] getDriverName() {
			return new String[]{"com.mysql.cj.jdbc.Driver","com.mysql.jdbc.Driver"};
		}
	},
	SQLSERVER {
		public Integer getCode() {
			return 3;
		}

		public String[] getDriverName() {
			return new String[]{"com.microsoft.sqlserver.jdbc.SQLServerDriver"};
		}
	},
	ORACLE {
		public Integer getCode() {
			return 2;
		}

		public String[] getDriverName() {
			return new String[]{"oracle.jdbc.driver.OracleDriver"};
		}
	},
	POSTGRESQL {
		public Integer getCode() {
			return 5;
		}

		public String[] getDriverName() {
			return  new String[]{"org.postgresql.Driver"};
		}
	},
	SQLITE {
		public Integer getCode() {
			return 6;
		}

		public String[] getDriverName() {
			return  new String[]{"org.sqlite.JDBC"};
		}
	},

	MARIADB {
		public Integer getCode() {
			return 7;
		}

		public String[] getDriverName() {
			return  new String[]{"com.mysql.jdbc.Driver"};
		}
	},
	CLICKHOUSE {
		public Integer getCode() {
			return 8;
		}

		public String[] getDriverName() {
			return  new String[]{"ru.yandex.clickhouse.ClickHouseDriver"};
		}
	};


	public static DataSourceDriverEnum dataSourceDriver(String driverName){
		for(DataSourceDriverEnum dataSourceDriverEnum:DataSourceDriverEnum.values()){
			boolean isThisDriver = Arrays.asList(dataSourceDriverEnum.getDriverName()).contains(driverName);
			if(isThisDriver){
				return dataSourceDriverEnum;
			}
		}
		return null;
	}

	public static DataSourceDriverEnum dataSource(String dbName){
		for(DataSourceDriverEnum dataSourceDriverEnum:DataSourceDriverEnum.values()){
			boolean isThisDriver = dbName.equals(dataSourceDriverEnum.name().toLowerCase());
			if(isThisDriver){
				return dataSourceDriverEnum;
			}
		}
		return null;
	}
}
